trigger UniqueAuthors on MZ_Playlist_Entry__c (after insert, after delete) {
    map<id,MZ_Playlist_Entry__c> entries = new map<id,MZ_Playlist_Entry__c>(trigger.newMap);
    Map<id,Set<String>> playlistsMap= new Map<id,Set<String>>();
    for(MZ_Playlist_Entry__c a: entries.values()){
        if(!playlistsMap.containsKey(a.MZ_Playlist_ref__c)){
            playlistsMap.put(a.MZ_Playlist_ref__c, new Set<String>()); 
            
        }
            playlistsMap.get(a.MZ_Playlist_ref__c).add(a.MZ_Author__c);
    }
  //  List<MZ_Playlist_Entry__c> entriesList= new List<MZ_Playlist_Entry__c>([Select MZ_Playlist_ref__c , MZ_Author__c FROM MZ_Playlist_Entry__c WHERE MZ_Playlist_ref__c IN :playlistsMap.keySet()]);
 /*   for(MZ_Playlist_Entry__c b: entriesList){
        if(playlistsMap.containsKey(b.MZ_Playlist_ref__c)){
            playlistsMap.get(b.MZ_Playlist_ref__c).add(b.MZ_Author__c);
            
        }else{
            playlistsMap.put(b.MZ_Playlist_ref__c, new Set<String>());
        }

    }*/
    Map<Id,MZ_Playlist__c> palylist= new Map<Id,MZ_Playlist__c>([SELECT MZ_Unique_Authors_Number__c from MZ_Playlist__c WHERE Id IN :playlistsMap.keySet() ]);
    for(MZ_Playlist__c c: palylist.values()){
        c.MZ_Unique_Authors_Number__c= playlistsMap.get(c.id).size();
      
    }
    update palylist.values();
}